package br.com.agiledev.webscrum.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.ForeignKey;

@Entity
@SequenceGenerator(name = "impediment", sequenceName = "se_impediment")
@NamedQueries ({
    @NamedQuery(name = "Impediment.porSprint", query = "select imp from Impediment imp where imp.dailyScrum.sprint = :sprint order by imp.oid desc"),
    @NamedQuery(name = "Impediment.porSprintForaDailyScrum", query = "select imp from Impediment imp where imp.dailyScrum.sprint = :sprint and imp.dailyScrum != :dailyScrum order by imp.oid desc")
})
public class Impediment implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "impediment")
    private Long oid;

    @Column(length = 255, nullable = false)
    private String descricao;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @ForeignKey(name = "fk_impediment_dailyscrum")
    private DailyScrum dailyScrum;

    public Impediment() {
	super();
    }

    public Long getOid() {
	return this.oid;
    }

    public void setOid(Long oid) {
	this.oid = oid;
    }

    public String getDescricao() {
	return this.descricao;
    }

    public void setDescricao(String descricao) {
	this.descricao = descricao;
    }

    public DailyScrum getDailyScrum() {
	return this.dailyScrum;
    }

    public void setDailyScrum(DailyScrum dailyScrum) {
	this.dailyScrum = dailyScrum;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((oid == null) ? 0 : oid.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	Impediment other = (Impediment) obj;
	if (oid == null) {
	    if (other.oid != null)
		return false;
	} else if (!oid.equals(other.oid))
	    return false;
	return true;
    }

}
